﻿using Glue;
using Xunit;

namespace GlueTests.MappingTests
{
    public class When_handling_simplified_mapping_and_property_names
    {
        private readonly Mapping<Outer1, Outer2> mapping;

        public class Outer1
        {
            public int JustAProperty { get; set; }
            public int JustAnotherProperty { get; set; }
            public Inner1 Inner { get; set; }
        }

        public class Inner1
        {
            public InnerInner1 Inner { get; set; }
            public int JustAProperty { get; set; }
        }

        public class InnerInner1
        {
            public int JustAProperty { get; set; }
        }

        public class Outer2
        {
            public int AProperty { get; set; }
            public Inner2 Inner { get; set; }
            public int EqualNameInOuterAndInnerScope { get; set; }
        }

        public class Inner2
        {
            public int EqualNameInOuterAndInnerScope { get; set; }
            public int AProperty { get; set; }
        }


        public When_handling_simplified_mapping_and_property_names()
        {
            mapping = new Mapping<Outer1, Outer2>();
        }

        [Fact]
        public void Should_not_fail_when_equal_names_at_different_nested_levels()
        {
            
            mapping.Relate(x => x.JustAProperty, y => y.EqualNameInOuterAndInnerScope);
            mapping.Relate(x => x.JustAnotherProperty, y => y.Inner.EqualNameInOuterAndInnerScope);
        }

        [Fact]
        public void Relations_with_different_properties_but_properties_with_equal_names_should_not_replace_eachother()
        {
            mapping.Relate(x=>x.Inner.JustAProperty,y=>y.AProperty);
            mapping.Relate(x => x.Inner.Inner.JustAProperty, y => y.Inner.AProperty);
            Assert.Equal(2, mapping.Relations.Count);
        }


    }
}
